import json

import requests

from project.settings import APPID, APPSECRET


def get_data(code):
    appid = APPID
    appsecret = APPSECRET
    api = "https://api.weixin.qq.com/sns/jscode2session"
    params = '?app_id=%s' + '&secret=%s' + '&js_code=%s' + '&grant_type=authorization_code'.format(appid, appsecret,
                                                                                                   code)
    url = api + params
    r = requests.get(url, )
    # r.encoding='utf-8'
    # r=str(r.text)
    print(r.text)
    data = json.loads(r.text)
    print(data)
    # return data
    return data